# 欢迎来到对抗路！！！
# 现在是北京时间: 2023/8/28 22:14
# Keep and you will win！！！
# 闭包， nonlocal

# def outer(num1=0):
#     def inner(num2):
#         nonlocal num1
#         num1 += num2
#         print(f"{num1}")
#     return inner
#
#
# fun = outer()
# fun(10)
# fun(20)
# fun(30)

# 使用闭包函数实现atm取款机
def account_create(initial_account=0):
    def atm_(money, deposit=True):
        nonlocal initial_account
        if deposit:
            initial_account += money
            print(f"存款+{money}元，账户余额：{initial_account}元")
        else:
            initial_account -= money
            print(f"取款-{money}元，账户余额：{initial_account}元")

    return atm_


atm = account_create()
atm(100)
atm(100)
atm(200)
atm(100, deposit=False)
